/**
 * 
 */
package com.sx.article.biz.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONArray;
import com.sx.article.biz.IKeyWordBiz;
import com.sx.article.dao.IKeyWordDao;
import com.sx.article.entity.KeyWordAndArticleUnionEntity;
import com.sx.article.entity.KeyWordsEntity;
import com.sx.feesunit.exception.SXException;

/**
 * @author Administrator
 * 关键字业务类代码
 */
public class KeyWordBiz implements IKeyWordBiz {
	private Log log = LogFactory.getLog(this.getClass());
	private IKeyWordDao keyworddao;
	
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#deleteKeyWordsByArticleId(java.lang.Integer)
	 */
	public boolean deleteKeyWordsByArticleId(Integer aid) throws SXException {
		boolean flag = false;
		try {
			flag = keyworddao.deleteKeyWordsByArticleId(aid);
		} catch (Exception e) {
			log.error("获取索引词信息失败",e);
			throw new SXException(e);
			// TODO: handle exception
		}
		return flag;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#findKeyWordsCount(com.sx.article.entity.KeyWordsEntity)
	 */
	public String findKeyWordsCount(KeyWordsEntity keyword,String queryname) throws SXException {
		String count = null;
		try {
			queryname +="Count";
			count =  keyworddao.findKeyWordsCount(keyword,queryname);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("获取索引字信息数量",e);
		}
		return count;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#findKeyWordsJSONString(com.sx.article.entity.KeyWordsEntity)
	 */
	public String findKeyWordsJSONString(KeyWordsEntity keyword,String queryname)
			throws SXException {
		// TODO Auto-generated method stub
		String str = null;
		try {
			String data = JSONArray.toJSONString(this.findKeyWords(keyword,queryname));
			String count = this.findKeyWordsCount(keyword,queryname);
			str = "{totalCount:"+count+",data:"+data+"}";
		} catch (Exception e) {
			log.error("获取索引词信息失败",e);
			// TODO: handle exception
		}
		return str;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#findKeyWords(com.sx.article.entity.KeyWordsEntity)
	 */
	public List<KeyWordsEntity> findKeyWords(KeyWordsEntity keyword,String queryname) throws SXException {
		// TODO Auto-generated method stub
		List<KeyWordsEntity> list = new ArrayList<KeyWordsEntity>();
		try {
			list = keyworddao.findKeyWords(keyword,queryname);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("获取索引字信息",e);
		}
		return list;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#deleteKeyWords(com.sx.article.entity.KeyWordsEntity)
	 */
	public boolean deleteKeyWords(KeyWordsEntity keyword) throws SXException {
		// TODO Auto-generated method stub
		boolean flag = false;
		try {
			flag = keyworddao.deleteKeyWords(keyword);
		} catch (Exception e) {
			log.error("获取索引词信息失败",e);
			throw new SXException(e);
			// TODO: handle exception
		}
		return flag;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#findKeyWordsJSONString(com.sx.article.entity.KeyWordsEntity)
	 */
	public String findKeyWordsJSONString(KeyWordsEntity keyword)
			throws SXException {
		// TODO Auto-generated method stub
		String str = null;
		try {
			String data = JSONArray.toJSONString(this.findKeyWords(keyword));
			String count = this.findKeyWordsCount(keyword);
			str = "{totalCount:"+count+",data:"+data+"}";
		} catch (Exception e) {
			log.error("获取索引词信息失败",e);
			// TODO: handle exception
		}
		return str;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#findKeyWords(com.sx.article.entity.KeyWordsEntity)
	 */
	public List<KeyWordsEntity> findKeyWords(KeyWordsEntity keyword)
			throws SXException {
		// TODO Auto-generated method stub
		List<KeyWordsEntity> list = new ArrayList<KeyWordsEntity>();
		try {
			list = keyworddao.findKeyWords(keyword);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("获取索引字信息",e);
		}
		return list;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#findKeyWordsCount(com.sx.article.entity.KeyWordsEntity)
	 */
	public String findKeyWordsCount(KeyWordsEntity keyword) throws SXException {
		String count = null;
		try {
			count =  keyworddao.findKeyWordsCount(keyword);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("获取索引字信息数量",e);
		}
		return count;
	}
	/**
	 *新增索引字 
	 **/
	public Integer addKeyWord(KeyWordsEntity keyword) throws SXException{
		Integer id = null;
		try {
			id = keyworddao.addKeyWord(keyword);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("新增关键字失败",e);
			throw new SXException(e);
		}
		return id;
	}
	/* (non-Javadoc)
	 * @see com.sx.article.biz.IKeyWordBiz#addKeyWordAndArticeUnion(com.sx.article.entity.KeyWordsEntity)
	 */
	public Integer addKeyWordAndArticeUnion(KeyWordAndArticleUnionEntity kwe) throws SXException{
		// TODO Auto-generated method stub
		Integer id = null;
		try {
			id = keyworddao.addKeyWordAndArticeUnion(kwe);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("新增关键字和文章信息关联失败",e);
			throw new SXException(e);
		}
		return id;
	}
	/**
	 * @return the keyworddao
	 */
	public IKeyWordDao getKeyworddao() {
		return keyworddao;
	}
	/**
	 * @param keyworddao the keyworddao to set
	 */
	public void setKeyworddao(IKeyWordDao keyworddao) {
		this.keyworddao = keyworddao;
	}
	
}
